<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <!-- 
        单项数据流：
          数据流向只能从父组件流入到子组件，通过props
          只能修改父组件的值，子组件的props会同步更新
          在子组件不能去修改props的值
       -->
      <h2>单向数据流 - {{ count }}</h2>
      <button @click="count++">btn</button>
      <child :count="count" @double="double"></child>
    </div>

    <script src="./lib/Vue3.js"></script>
    <script>
      const { createApp } = Vue;

      const Child = {
        props: {
          count: Number,
        },
        template: `
          <div>child子组件 - {{ count }} - <button @click="handleClick">btn2</button></div>
        `,
        methods: {
          handleClick() {
            this.$emit("double");
          },
        },
      };

      createApp({
        data() {
          return {
            count: 5,
          };
        },
        methods: {
          double() {
            this.count *= 2;
          },
        },
        components: {
          Child,
        },
      }).mount("#app");
    </script>
  </body>
</html>
